/**
 *			\author ITII - ISEN - P6
 *			\author Benjamin Mur
 *			\file TcpServer.h
 *			\version 0.1
 *			\date 06/09/2010
 */

#ifndef TCPSERVER_H_INCLUDED
#define TCPSERVER_H_INCLUDED

#include <netinet/in.h>

    typedef int SOCKET;
    typedef struct sockaddr_in SOCKADDR_IN;
    typedef struct sockaddr SOCKADDR;

class TcpServer
{

    private:    /*Socket Server*/
                SOCKADDR_IN     _sockin;
                SOCKET          _sock;
                socklen_t       _sizesock;
                /*Socket Client*/
                SOCKADDR_IN     _csockin;
                SOCKET          _csock;
                socklen_t       _csizesock;

                int             _sock_err;
                bool		_init;

    private:
                int            CreateSocket();
                int            ConfigSocket(int port);
                void           CloseSocket(SOCKET* socket);
                int            WaitingClient();

	public:
                                TcpServer( int port = 25 );
                                ~TcpServer();

                int             serverSend(char* buffer,
                                    int   buferSize);

                int             serverReceive(char* buffer,
                                        int bufferSize);
		bool		isInit() const;
};

#endif // TCPSERVER_H_INCLUDED
